home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.3d26 source
/
tn3270
/
writescr.c
< prev
next >
Wrap
Text File
|
1991-05-23
|
35KB
|
1,532 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.3d21, January 17, 1991
* Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#define __SEG__ 3270seg1
#include "maclib.h"
#include "termdef.h"
#include "globals.h"
#include "palette.h"
long GetA5();
extern char vmxbgn, vmxsub;
extern Rect statRect, textRect, cposRect;
extern short hpixsize, vpixsize, saveoff;
extern short htxtstrt, vtxtstrt, vtxtsize, htxtsize, curvsize, curhsize;
extern short scrhoff, scrhsize;
extern short x_origin, y_origin;
extern short maxoff, maxcnt;
extern PaletteHandle myPalette;
extern char colorfield;
extern RGBColor realblack, realwhite;
extern DialogPtr xdlgptr;
extern unsigned char cutflag;
extern unsigned char nlbuff[];
extern char statcpos; /* if true, only draw cursor position */
Rect gr_rect; /* grow icon rectangle */
selcoord lastsel; /* points for last text selection */
static char framedfield; /* screen contains framed fields */
invldscr()
{
register short rc;
GrafPtr gp;
if (sw_bgrnd) {
sw_upd = 1;
return;
}
if (pndinv) return;
GetPort(&gp);
rc = 0;
if (!(serflg || tcpflg)) {
SetPort(WritePtr);
if (textmap) {
setgdev();
rc = writescr(0);
resetgdev();
}
}
else needwrite = 1;
SetPort(myWindow);
if (rc == 0) InvalRect(&textRect);
SetPort(gp);
checkpos();
}
checkpos()
{
GrafPtr gp;
if (!cs.curpos) return;
statcpos = 1;
newstat();
statcpos = 0;
}
writescr(printflag)
char printflag;
{
register unsigned short a, i, cattr, fattr, start, count;
unsigned short offset, lastfield;
char geflg, g;
/* char msg[64]; !!!!! */
static unsigned long * Ticks = (unsigned long *)0x16a;
unsigned long stasklim;
/* if (cs.dblevel == 2) ticktime = (*Ticks); !!!!! */
/* get field attribute for first screen position, even if it */
/* is defined by a subsequent field wrapping to the start. */
fattr = lastfield = 0;
if (fmtscrn) {
if (atrbuff[0] & 0x8000) {
lastfield = atrbuff[0] & 0x3fdf;
fattr = lastfield & 0x3f1f;
}
else for (i = maxoff; i > 0; i--)
if (atrbuff[i] & 0x8000) {
lastfield = atrbuff[i] & 0x3fdf;
fattr = lastfield & 0x3f1f;
break;
}
}
WriteCurr = 0;
if (printflag == 0) EraseRect(&textRect);
framedfield = 0;
cattr = fattr;
if (tcpflg) stasklim = (*Ticks) + 4;
for (start = 0; start < maxcnt; start += scrhsize) {
if (pndinv) return(1);
if (tcpflg) {
if ((*Ticks) > stasklim) {
myStask();
stasklim = (*Ticks) + 4;
}
}
count = 0;
geflg = 0;
offset = start;
MoveTo(htxtstrt, WriteCurr*vtxtsize + vtxtstrt);
for (i=0; i < scrhsize; i++) {
a = atrbuff[start+i];
g = (a & 0x40c0) != 0;
a &= 0xbfff;
if (a & 0x8000) {
dfield(offset, count, lastfield, cattr, geflg);
/* attribute byte is a field by itself */
offset = start + i;
count = -1; /* indicates attribute byte */
fattr = a & 0x3fff;
dfield(offset, count, fattr, fattr, 0);
lastfield = fattr & 0x3fdf; /* selection doesn't propagate */
fattr = lastfield & 0x3f1f;
cattr = fattr;
count = 0;
geflg = 0;
offset = start + i + 1;
}
else {
a &= 0x3f3f;
if ((a == 0) && (cattr == fattr)) {
count++;
geflg |= g;
continue;
}
if (a == cattr) {
count++;
geflg |= g;
continue;
}
/* else start new field */
dfield(offset, count, lastfield, cattr, geflg);
count = 1;
offset = start + i;
cattr = a;
geflg = g;
}
}
dfield(offset, count, lastfield, cattr, geflg);
WriteCurr ++;
}
if (printflag) return(0);
x = curadr%scrhsize;
y = curadr/scrhsize;
defcursor(x, y); /* define er rectangle for cursor */
if (!textmap) drawcurs(0);
/* if (cs.dblevel == 2) { !!!!!
ticktime = (*Ticks) - ticktime;
sprintf(msg, "time for writescr: %ld ticks", ticktime);
putln(msg);
} */
if (pndinv) return(1);
else return(0);
}
newcur()
{
GrafPtr gp;
if (sw_bgrnd) {
sw_upd = 1;
return;
}
GetPort(&gp);
SetPort(myWindow);
if (textmap) InvalRect(&er);
else drawcurs(1);
x = curadr%scrhsize;
y = curadr/scrhsize;
defcursor(x, y); /* define er rectangle for cursor */
if (textmap) InvalRect(&er);
else drawcurs(0);
SetPort(gp);
checkpos();
}
newchar(offset, value, atr, fattr)
short offset, atr, fattr;
unsigned char value;
{
short newatr, selattr;
chrbuff[offset] = value;
if (cutflag) { /* allow deletion of selection attribute */
atrbuff[offset] = atr;
}
else { /* preserve selection attribute */
selattr = atrbuff[offset] & 0x0020;
atrbuff[offset] = (atr & 0xffdf) | selattr;
}
if (sw_bgrnd) {
sw_upd = 1;
return;
}
newatr = fattr & 0x3fff;
/* if (atr & 0x4000) newatr |= 0x4000; */
if (in_len == 0) {
in_len = 1;
in_off = offset;
in_atr = newatr;
return;
}
if ( (in_atr != newatr) || (in_off/scrhsize != offset/scrhsize) ||
(offset-in_off-in_len > 0) || (in_off-offset > 1) ) {
dchar(in_off, in_len, in_atr);
in_len = 1;
in_off = offset;
in_atr = newatr;
return;
}
in_len++;
if (in_off-offset == 1) in_off--;
}
dchar(offset, len, fattr)
short offset, len, fattr;
{
short i, selattr, dstart, dlen;
if (len < 1) return;
if (len == 1) {
seldchar(offset, len, atrbuff[offset] & 0x3f3f, fattr);
return;
}
selattr = atrbuff[offset] & 0x3f3f;
dstart = offset;
dlen = 1;
for (i=1; i < len; i++)
if ((atrbuff[offset+i] & 0x3f3f) != selattr) {
seldchar(dstart, dlen, selattr, fattr);
selattr = atrbuff[offset+i] & 0x3f3f;
dstart = offset+i;
dlen = 1;
}
else dlen++;
seldchar(dstart, dlen, selattr, fattr);
}
seldchar(offset, len, selattr, fattr)
short offset, len, selattr, fattr;
{
Rect r;
register short x, y;
GrafPtr gp;
unsigned char attrbits;
RGBColor rgbtemp;
short fnum, chrtop;
char prot, fieldfont;
prot = (fattr & 0x2000) != 0;
fieldfont = (fattr & 0x00c0) >> 6;
fattr &= 0xff3f;
getdspatr(&attrbits, 0L, &rgbtemp, selattr, fattr);
GetPort(&gp);
SetPort(WritePtr);
if (textmap) setgdev();
y = offset/scrhsize;
x = offset%scrhsize;
chrtop = r.top = y*vtxtsize;
if (htxtstrt == 0) r.top--; /* adjust for 12-point */
r.left = htxtstrt+x*htxtsize;
r.bottom = r.top+vtxtsize;
r.right = r.left + len * htxtsize;
if (!textmap)
if ((curadr >= offset) && (curadr < offset+len)) drawcurs(1);
if (framedfield) { /* adjust to not erase any frames on screen */
r.bottom--;
}
if (colormac)
if (attrbits & 0x20) { /* reversed field */
RGBBackColor(&rgbtemp);
if (cs.invertbw) GetEntryColor(myPalette, RGBwhite, &rgbtemp);
else GetEntryColor(myPalette, RGBblack, &rgbtemp);
RGBForeColor(&rgbtemp);
}
else RGBForeColor(&rgbtemp); /* normal field */
EraseRect(&r);
if (!(attrbits & 0x80)) { /* displayable */
MoveTo(r.left, vtxtstrt+chrtop);
txtfield(offset, len, attrbits, prot, fieldfont);
/* if (fattr & 0x4000) fnum = APLFONT;
else fnum = stdfont;
if (attrbits & 0x08) fnum += 2;
if (fnum != stdfont) TextFont(fnum);
myDrawText(chrbuff, offset, len, fnum, prot);
if (fnum != stdfont) TextFont(stdfont); */
if (attrbits & 0x10) {
MoveTo(r.left, chrtop+vtxtstrt+(curvsize>>2)-3);
LineTo(r.right+1, chrtop+vtxtstrt+(curvsize>>2)-3);
}
if ((!colormac) && (attrbits & 0x20)) InvertRect(&r);
}
if (colormac && (attrbits & 0x20)) {
GetEntryColor(myPalette, RGBback, &rgbtemp);
RGBBackColor(&rgbtemp);
}
SetPort(myWindow);
if (textmap) {
resetgdev();
if (r.top < inrect.top) inrect.top = r.top;
if (r.left < inrect.left) inrect.left = r.left;
if (r.bottom > inrect.bottom) inrect.bottom = r.bottom;
if (r.right > inrect.right) inrect.right = r.right;
}
else if ((curadr >= offset) && (curadr < offset+len)) drawcurs(0);
SetPort(gp);
}
newwrite(upd)
char upd;
{
GrafPtr gp;
BitMap * srcbits;
if (sw_bgrnd) return;
if (in_len > 0) {
dchar(in_off, in_len, in_atr);
in_len = 0;
}
if (!textmap) return;
GetPort(&gp);
SetPort(myWindow);
InvalRect(&inrect);
inrect.top = inrect.left = 32767;
inrect.bottom = inrect.right = -32767;
SetPort(gp);
}
dfield(offset, count, fattr, cattr, g)
short offset, count, fattr, cattr;
char g;
{
struct Rect z;
unsigned char attrbits, trim;
short xend, yend, txtcount, txtoff, adjcount, adjoff;
RGBColor rgbfield, rgbrev;
char prot, fieldfont;
short fnum;
if (count == 0) return;
fieldfont = (fattr & 0x00c0) >> 6;
fattr &= 0xff3f;
/* get attribute definition for this field */
prot = (fattr & 0x2000) != 0;
trim = 1;
getdspatr(&attrbits, &trim, &rgbfield, cattr, fattr);
if (count == -1) {
attrbits = cs.attrmap[6];
trim = 0;
count = 1;
if (cattr & 0x0020) {
attrbits &= 0x8f;
attrbits |= 0x20;
}
}
/* remember where to end up when done */
xend = htxtstrt + (offset%scrhsize)*htxtsize + count*htxtsize;
yend = WriteCurr*vtxtsize + vtxtstrt;
/* if appropriate, calculate new count and offset to eliminate leading
and trailing blanks and nulls */
adjcount = txtcount = count;
adjoff = txtoff = offset;
calctrim(&txtoff, &txtcount); /* don't draw blanks and nulls */
if (!(fattr & 0x2000)) trim = 0; /* unprotected not trimmed */
if (trim) {
adjcount = txtcount;
adjoff = txtoff;
}
/* define nominal rectangle for this update */
z.top = WriteCurr * vtxtsize;
z.bottom = z.top + vtxtsize;
if (htxtstrt == 0) { /* adjust for 12-point */
z.top--;
z.bottom--;
}
z.left = htxtstrt + (adjoff%scrhsize) * htxtsize;
z.right = z.left + adjcount * htxtsize;
/* define colors for normal or reversed field */
if (colormac)
if (attrbits & 0x20) {
RGBBackColor(&rgbfield);
if (adjcount > 0) {
if (attrbits & 0x40) {
z.left -= 1;
z.right += 1 - htxtstrt;
}
EraseRect(&z);
if (attrbits & 0x40) {
z.left += 1;
z.right -= 1 - htxtstrt;
}
}
GetEntryColor(myPalette, RGBback, &rgbrev);
RGBBackColor(&rgbrev);
if (cs.invertbw) GetEntryColor(myPalette, RGBwhite, &rgbrev);
else GetEntryColor(myPalette, RGBblack, &rgbrev);
RGBForeColor(&rgbrev);
}
else RGBForeColor(&rgbfield);
/* draw text if not non-display or all blanks or nulls */
if (txtoff != offset) MoveTo(htxtstrt+(txtoff%scrhsize)*htxtsize, yend);
if (!((attrbits & 0x80) || (txtcount == 0)))
if (g) {
txtfield(txtoff, txtcount, attrbits, prot, fieldfont);
}
else {
if (fieldfont == 1) fnum = APLFONT;
else fnum = stdfont;
if (attrbits & 0x08) fnum += 2;
if (fnum != stdfont) TextFont(fnum);
myDrawText(chrbuff, txtoff, txtcount, fnum, prot);
if (fnum != stdfont) TextFont(stdfont);
}
MoveTo(xend, yend);
/* return if no other attributes */
if (!(attrbits & 0x70)) return;
/* return if trimming has removed field */
if (adjcount == 0) return;
/* frame if requested */
if (attrbits & 0x40) {
z.top -= 1;
z.left -= 2;
z.right += 2 - htxtstrt;
if (colormac) RGBForeColor(&rgbfield);
FrameRect(&z);
z.top += 1;
z.bottom -= 1;
z.left += 1;
z.right -= 1;
framedfield = 1;
}
/* underline if requested */
if (attrbits & 0x10) {
if (colormac)
if (attrbits & 0x20) RGBForeColor(&rgbrev);
else RGBForeColor(&rgbfield);
MoveTo(z.left, yend+(curvsize>>2)-3);
LineTo(z.right-1, yend+(curvsize>>2)-3);
}
/* reverse if requested */
if ((!colormac) && (attrbits & 0x20)) InvertRect(&z);
/* leave pen ready for next character */
MoveTo(xend, yend);
}
calctrim(offset, count)
short * offset;
short * count;
{
register short adjoff, adjcount, i, j, k;
adjcount = j = (*count);
adjoff = k = (*offset);
for (i = 0; i < j; i++) {
if ((chrbuff[k] == 0x40) || (chrbuff[k] == 0x00)) {
adjoff++;
adjcount--;
}
else break;
k++;
}
j = adjcount;
k = adjoff + adjcount - 1;
for (i = 0; i < j; i++) {
if ((chrbuff[k] == 0x40) || (chrbuff[k] == 0x00)) adjcount--;
else break;
k--;
}
(*offset) = adjoff;
(*count) = adjcount;
}
getdspatr(atr_result, trim_result, color_result, cattr, fattr)
unsigned char * atr_result;
unsigned char * trim_result;
RGBColor * color_result;
register unsigned short cattr;
register unsigned short fattr;
{
register unsigned char attrbits;
unsigned char exthi, color, trim, cnum;
static RGBColor * HiliteRGB = (RGBColor *)0xda0;
if (trim_result != 0) trim = (*trim_result);
/* determine extended highlighting value to use */
exthi = (cattr & 0x0018) >> 3;
if (exthi == 0) exthi = (fattr & 0x0018) >> 3;
/* get default, highlight, or non-display attribute */
switch ((fattr & 0x0C00) >> 10) {
case 0:
case 1: attrbits = cs.attrmap[0];
break;
case 2: attrbits = cs.attrmap[1];
break;
case 3: attrbits = cs.attrmap[2];
exthi = 0; /* non-display cancels ext. high */
trim = 0;
break;
default: attrbits = 0;
break;
}
/* add extended highlighting to basic attributes */
switch (exthi) {
case 0: break;
case 1: attrbits |= cs.attrmap[4];
break;
case 2: attrbits |= cs.attrmap[3];
trim = 0;
break;
case 3: attrbits |= cs.attrmap[5];
trim = 0;
break;
default: break;
}
/* adjust attrbits for mouse selection field */
if (cattr & 0x0020) {
attrbits &= 0x8f; /* cancel frame, reverse, underline */
attrbits |= 0x20; /* set reverse bit */
trim = 0; /* don't trim */
}
/* determine color value to use */
if (colormac) {
if (cattr & 0x0020) { /* use highlight color for selection text */
(*color_result) = (*HiliteRGB);
if ((((*color_result) == realblack) && (!cs.invertbw)) ||
(((*color_result) != realblack) && cs.invertbw)) {
(*color_result).red = 0xffff - (*color_result).red;
(*color_result).green = 0xffff - (*color_result).green;
(*color_result).blue = 0xffff - (*color_result).blue;
}
}
else {
color = cattr & 0x0007;
if (color == 0) color = fattr & 0x0007;
if (color == 0) {
if (fattr & 0x2000) { /* protected */
if ((fattr & 0x0c00) == 0x0800) { /* high-intensity */
color = 7; /* white */
}
else {
if (cs.basecolor || colorfield) color = 4; /* green */
else color = 1; /* blue */
}
}
else { /* unprotected */
if ((fattr & 0x0c00) == 0x0800) { /* high-intensity */
if (cs.basecolor || colorfield) color = 7; /* white */
else color = 2; /* red */
}
else {
color = 4; /* green */
}
}
}
switch(color) {
case 1: cnum = RGBblue;
break;
case 2: cnum = RGBred;
break;
case 3: cnum = RGBpink;
break;
case 5: cnum = RGBturquoise;
break;
case 6: cnum = RGByellow;
break;
case 7: if (cs.invertbw) cnum = RGBblack;
else cnum = RGBwhite;
break;
default: cnum = RGBgreen;
break;
}
GetEntryColor(myPalette, cnum, color_result);
}
}
if (trim_result != 0) (*trim_result) = trim;
(*atr_result) = attrbits;
}
txtfield(offset, count, attrbits, prot, fieldfont)
short offset, count;
unsigned char attrbits;
char prot, fieldfont;
{
register short start, len, lim, f, i, fnum;
register unsigned char font;
start = offset;
len = 0;
lim = offset + count;
if (atrbuff[offset] & 0x4000) {
font = 1;
}
else {
font = (atrbuff[offset] & 0x00c0) >> 6;
}
if (font == 0) font = fieldfont;
for (i=offset; i < lim; i++) {
if (atrbuff[i] & 0x4000) {
f = 1;
}
else {
f = (atrbuff[i] & 0x00c0) >> 6;
}
if (f == 0) f = fieldfont;
if (font == f) len++;
else {
if (font == 1) fnum = APLFONT;
else fnum = stdfont;
if (attrbits & 0x08) fnum += 2;
TextFont(fnum);
myDrawText(chrbuff, start, len, fnum, prot);
font = f;
start = i;
len = 1;
}
}
if (font == 1) fnum = APLFONT;
else fnum = stdfont;
if (attrbits & 0x08) fnum += 2;
TextFont(fnum);
myDrawText(chrbuff, start, len, fnum, prot);
if (fnum != stdfont) TextFont(stdfont);
}
myDrawText(textBuf, firstByte, byteCount, font, prot)
register unsigned char *textBuf;
register short firstByte, byteCount;
short font;
char prot;
{
register short i, j;
if (byteCount <= 0) return;
if (nl_handle == 0) { /* no translation */
if (((font == ALAFONT) || (font == BOLDALA)) && prot && (!plainala)) {
ALADrawText(textBuf, firstByte, byteCount);
}
else {
DrawText(textBuf, firstByte, byteCount);
}
return;
}
if ((font == stdfont) || (font == (stdfont+2))) {
j = firstByte;
for (i=0; i < byteCount; i++) {
nlbuff[i] = nltab[textBuf[j++]];
}
DrawText(nlbuff, 0, byteCount);
}
else { /* translation does not apply to APL */
DrawText(textBuf, firstByte, byteCount);
}
}
ALADrawText(textBuf, firstByte, byteCount)
unsigned char *textBuf;
short firstByte, byteCount;
{
register unsigned char *sptr;
register short i, textlen, state;
unsigned char *textptr;
short blankcount;
short alatype();
sptr = textBuf+firstByte;
blankcount = textlen = 0;
textptr = sptr;
state = 0;
for (i=firstByte; i < firstByte+byteCount; i++) {
switch(alatype(sptr)) {
case 0: /* normal character */
switch (state) {
case 0: /* normal */
textlen++;
break;
case 1: /* last char. diacritic */
if (textlen > 1) {
DrawText(textptr, 0, textlen-1);
textptr += textlen-1;
}
drawdc(*textptr, *sptr);
movechr(-1);
blankcount++;
textptr = sptr;
textlen = 1;
state = 0;
break;
default:
break;
}
break;
case 1: /* blank */
switch (state) {
case 0: /* pending blanks */
if (blankcount == 0) {
textlen++;
}
else {
DrawText(textptr, 0, textlen);
blankcount++;
movechr(blankcount);
blankcount = 0;
textptr = sptr + 1;
textlen = 0;
state = 0;
}
break;
case 1: /* last char. diacritic */
if (textlen > 1) {
DrawText(textptr, 0, textlen-1);
textptr += textlen-1;
}
drawdc(*textptr, *sptr);
blankcount++;
textptr = sptr + 1;
textlen = 0;
state = 0;
break;
default:
break;
}
break;
case 2: /* diacritic */
switch (state) {
case 0: /* normal */
case 1: /* last char. diacritic */
textlen++;
state = 1;
break;
default:
break;
}
break;
default:
break;
}
sptr++;
}
if (textlen > 0) {
DrawText(textptr, 0, textlen);
}
if (blankcount > 0) {
movechr(blankcount);
}
}
short alatype(s)
unsigned char *s;
{
register unsigned char c;
c = *s;
if ((c == 0x40) || (c == 0x00)) return(1); /* blank or null */
if ((c%16) < 10) return(0); /* normal character */
if (c < 0x80) return(0);
if ((c >= 0xa0) && (c <= 0xbf)) return(0);
if (c >= 0xf0) return(0);
return(2);
}
movechr(n)
short n;
{
FontInfo fi;
if (n == 0) return;
GetFontInfo(&fi);
Move(fi.widMax*n, 0);
}
drawdc(dc, c) /* draw diacritic, adjusting postion depending on
the character being modified */
register unsigned char dc;
register unsigned char c;
{
register char adjflag;
FontInfo fi;
adjflag = 0;
/* check for lowercase character */
if (c == 0x40) adjflag = 1;
else if ((c >= 0x52) && (c <= 0x58)) adjflag = 1;
else if ((c >= 0x81) && (c <= 0x85)) adjflag = 1;
else if ((c >= 0x87) && (c <= 0x88)) adjflag = 1;
else if ((c >= 0x94) && (c <= 0x99)) adjflag = 1;
else if (c == 0xa2) adjflag = 1;
else if ((c >= 0xa4) && (c <= 0xa9)) adjflag = 1;
if (adjflag) { /* check for upper diacritic */
if ((dc >= 0x8e) && (dc <= 0x8f)) adjflag = 0;
else if ((dc >= 0x9e) && (dc <= 0x9f)) adjflag = 0;
else if ((dc >= 0xca) && (dc <= 0xcc)) adjflag = 0;
else if (dc == 0xda) adjflag = 0;
else if ((dc >= 0xdc) && (dc <= 0xdd)) adjflag = 0;
else if (dc == 0xea) adjflag = 0;
else if (dc >= 0xec) adjflag = 0;
}
if (adjflag) {
GetFontInfo(&fi);
Move(0, fi.ascent/6); /* 1 for 9 pt., 2 for 12 pt. */
}
DrawChar(dc);
if (adjflag) Move(0, -(fi.ascent/6));
}
statline()
{
static char *days[] = {"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
};
static char *months[] = {"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
struct DateRec {
short year;
short month;
short day;
short hour;
short minute;
short second;
short DayOfWeek;
} today ;
static char result[24] = "";
static unsigned long * Ticks = (unsigned long *)0x16a;
static unsigned long last_t = 0;
static char last_stat_time = 99;
unsigned long t;
char errmsg[16];
char cpos;
char klock, kcode;
short vpos;
RGBColor rgbtemp;
if ((((*Ticks) - last_t) > 540) || (last_stat_time != cs.stat_time)) {
if (cs.stat_time >= 8) cs.stat_time -= 8;
last_stat_time = cs.stat_time;
if (cs.stat_time > 0) {
GetTime(&today);
if (cs.stat_time == 1) {
if (today.hour == 0) today.hour = 12;
if (today.hour > 12) today.hour -= 12;
}
sprintf(result,"%s %02d %s %02d:%02d",
days[today.DayOfWeek-1],today.day,months[today.month-1],
today.hour,today.minute);
}
else strcpy(result, "");
}
if (colormac && drawpict) {
GetEntryColor(myPalette, RGBback, &rgbtemp);
RGBBackColor(&rgbtemp);
}
EraseRect(&statRect);
TextFont(SYMBOLFONT);
TextSize(12);
if (colormac) {
GetEntryColor(myPalette, RGBstat, &rgbtemp);
RGBForeColor(&rgbtemp);
}
cpos = cs.curpos;
klock = kblock;
kcode = kblcode;
vpos = vpixsize - 12;
if (!klock) if (wr_active) {
klock = 1;
kcode = 2;
}
if (serflg) {
if (!connflg) {
MoveTo(-2, vpos);
DrawChar(0x00);
}
}
else if (tcpflg) {
if (logon) {
MoveTo(-2, vpos);
DrawChar(0x00);
}
}
else {
if (netconn) {
MoveTo(-2, vpos);
DrawChar(0x00);
}
}
if (online) {
MoveTo(7, vpos);
DrawChar(0x01);
}
MoveTo(16, vpos);
DrawChar(0x02);
if (insmode) {
MoveTo(290, vpos);
DrawChar(0x07);
}
if (klock || (vmxbgn && (!vmxsub))) {
MoveTo(61, vpos);
DrawChar(0x03);
}
if (klock && (kcode == 2)) {
MoveTo(74, vpos);
DrawChar(0x08);
}
if (klock && (kcode == 3)) {
MoveTo(74, vpos);
DrawChar(0x09);
DrawChar(0x0a);
DrawChar(0x0b);
DrawChar(0x0c);
}
if ((!klock) && (kb_err == 1)) {
MoveTo(74, vpos);
DrawChar(0x05);
}
if ((!klock) && (kb_err == 2)) {
MoveTo(74, vpos);
DrawChar(0x04);
DrawChar(0x05);
DrawChar(0x06);
}
if (ioerror != 0) {
MoveTo(150, vpos);
DrawChar(0x09);
DrawChar(0x0a);
DrawChar(0x0b);
DrawChar(0x0c);
MoveTo(175, vpos+1);
DrawChar(0x01);
}
if (vmxbgn || ftpcopen || ftpdopen || ftplopen) {
cpos = 0;
MoveTo(315, vpos);
DrawChar(0x0e);
Move(-2, 0);
DrawChar(0x04);
DrawChar(0x06);
Move(-2, 0);
DrawChar(0x0e);
}
if (klock && (kcode == 4)) {
TextFont(0);
TextSize(0);
MoveTo(74, vpos+1);
DrawString("Session");
}
TextFont(1);
TextSize(0);
if (klock && (kcode == 1)) {
MoveTo(74, vpos+1);
DrawString("SYSTEM");
}
if (klock && (kcode == 3)) {
MoveTo(112, vpos+1);
DrawString("590");
}
if ((!klock) && (kb_err == 1)) {
MoveTo(84, vpos);
DrawChar('>');
}
if ((!klock) && (kb_err == 3)) {
MoveTo(74, vpos+1);
DrawString("?+");
}
if (ioerror != 0) {
sprintf(errmsg,"%d",ioerror);
MoveTo(188, vpos+1);
DrawString(errmsg);
}
if (aplmode) {
MoveTo(245, vpos+1);
DrawString("APL");
}
if (cpos) {
sprintf(errmsg,"%02d/%02d",y+1,x+1);
MoveTo(cposRect.left, vpos+1);
DrawString(errmsg);
}
MoveTo(hpixsize-134, vpos+1);
DrawString(result);
MoveTo(-4,vpixsize-25);
LineTo(hpixsize-4,vpixsize-25);
TextFont(stdfont);
TextSize(cur_ptsize);
if (colormac && drawpict) {
if (cs.invertbw) GetEntryColor(myPalette, RGBwhite, &rgbtemp);
else GetEntryColor(myPalette, RGBblack, &rgbtemp);
RGBBackColor(&rgbtemp);
}
}
newstat()
{
long t;
GrafPtr gp;
BitMap * srcbits;
if (sw_bgrnd) {
sw_upd = 1;
return;
}
if (!textmap) { /* no screen buffer */
GetPort(&gp);
SetPort(myWindow);
statline();
/* ValidRect(&statRect); */ /* May need new grow icon */
SetPort(gp);
}
else { /* have screen buffer */
GetPort(&gp);
SetPort(WritePtr);
setgdev();
statline();
resetgdev();
SetPort(myWindow);
if (colormac) {
RGBForeColor(&realblack);
RGBBackColor(&realwhite);
srcbits = (BitMap *)(*(PixMapHandle)WritePort.portBits.baseAddr);
}
else {
srcbits = &WritePort.portBits;
}
if (statcpos) {
CopyBits(srcbits, &(myWindow->portBits),
&cposRect, &cposRect, srcCopy, 0L);
}
else {
CopyBits(srcbits, &(myWindow->portBits),
&statRect, &statRect, srcCopy, 0L);
}
/* ValidRect(&statRect); */ /* may need new grow icon */
SetPort(gp);
}
}
beep()
{
static short duration = 3;
static short sw_dur = 2;
OSErr rc;
OSErr mybeep();
if (apiopen) {
if (apiopenreq.hide) return;
}
if (sw_bgrnd) sw_beep = 1;
rc = mybeep();
if (rc == 0) return;
if (sw_bgrnd || mf_bgrnd) {
SysBeep(sw_dur);
SysBeep(sw_dur);
}
else SysBeep(duration);
}
OSErr mybeep()
{
OSErr rc, playrc;
SndChannelPtr default_scp;
extern sndproc();
SndCommand endcmd;
if (sndhandle == 0) return(1);
if (sndactive) {
SndDisposeChannel(scp, true);
sndactive = 0;
}
if (mf_bgrnd || sw_bgrnd) { /* play sound synchronously */
default_scp = 0;
rc = SndNewChannel(&default_scp, 0, 0L, 0L);
if (rc == noErr) {
playrc = SndPlay(default_scp, sndhandle, 0);
rc = SndDisposeChannel(default_scp, 0);
if (playrc == noErr) return(rc);
else return(playrc);
}
else {
return(rc);
}
}
rc = SndNewChannel(&scp, 0, 0L, sndproc);
if (rc != noErr) return(rc);
rc = SndPlay(scp, sndhandle, true);
if (rc != noErr) {
SndDisposeChannel(scp, true);
return(rc);
}
sndactive = 1;
endcmd.cmd = callBackCmd;
endcmd.param1 = 0;
endcmd.param2 = GetA5();
rc = SndDoCommand(scp, &endcmd, true);
if (rc != noErr) {
SndDisposeChannel(scp, true);
sndactive = 0;
}
return(rc);
}
sndend()
{
if (sndactive == 1) sndactive = 2; /* indicate dispose call needed */
}
drawcurs(restore) /* draw cursor in screen window */
char restore;
{
RGBColor rgbchar, mywhite, myblack, myback;
static RGBColor rgbbk; /* save for restore call */
unsigned short color, foffset, fattr, cattr;
unsigned char attrbits, trim;
short start, end, count, lend;
static unsigned char * hiliteMode = (unsigned char *)0x938;
if (!colormac) { /* just invert rectangle if no color */
InvertRect(&er);
return;
}
/* get colors we will need */
GetEntryColor(myPalette, RGBwhite, &mywhite);
GetEntryColor(myPalette, RGBblack, &myblack);
GetEntryColor(myPalette, RGBback, &myback);
if (!restore) { /* compute background if not restore call */
/* define attrbits and trim */
foffset = getattr(curadr);
fattr = atrbuff[foffset];
cattr = atrbuff[curadr];
trim = 1;
getdspatr(&attrbits, &trim, &rgbchar, cattr, fattr);
if (!(fattr & 0x2000)) trim = 0; /* unprotected not trimmed */
if (cattr & 0x8000) { /* handle attribute byte */
attrbits = cs.attrmap[6];
trim = 0;
}
/* determine background color */
/* reversed or underline cursor & field */
if ((attrbits & 0x20) || ((attrbits & 0x10) && (!cs.blockcurs))) {
if (trim) {
start = (curadr/scrhsize) * scrhsize;
lend = start + scrhoff;
if ((foffset >= start) && (foffset < curadr))
start = foffset+1;
end = start;
while (end < lend) {
end++;
if (atrbuff[end] & 0x8000) {
end--;
break;
}
}
count = end - start + 1;
calctrim(&start, &count);
end = start + count - 1;
if ((count > 0) && (curadr >= start) && (curadr <= end)) trim = 0;
}
if (trim) rgbbk = myback; /* trim actually applies where cursor is */
else if (((attrbits & 0x30) == 0x30) && (!cs.blockcurs)) {
/* reverse & underline & underline cursor */
if (cs.invertbw) rgbbk = mywhite;
else rgbbk = myblack;
}
else rgbbk = rgbchar; /* reverse | underline & underline cursor */
}
else rgbbk = myback; /* normal */
}
/* hilight (or unhilight) cursor rectangle */
if (cs.invertbw) {
HiliteColor(&myblack);
RGBBackColor(&rgbbk);
}
else {
RGBBackColor(&mywhite);
HiliteColor(&rgbbk);
}
(*hiliteMode) &= 0x7f;
InvertRect(&er);
/* restore what we changed */
HiliteColor(&realblack);
if (textmap) RGBBackColor(&realwhite);
else RGBBackColor(&myback);
}
defcursor(cx, cy)
short cx, cy;
{
er.left = cx * htxtsize;
er.top = cy * vtxtsize;
er.right = er.left + curhsize;
er.bottom = er.top + curvsize;
if (cs.blockcurs) return;
er.bottom -= (curvsize>>2) - 1;
er.top = er.bottom - 1;
}
justGrowIcon(rgnok)
char rgnok;
{
GrafPtr psave;
RGBColor myback, mystat, actback, actstat;
Rect temprect;
GetPort(&psave);
SetPort(myWindow);
if (!rgnok) SetClip(cliprgn);
if (colormac) {
GetEntryColor(myPalette, RGBback, &myback);
GetEntryColor(myPalette, RGBstat, &mystat);
actualcolor(&myback, &actback);
actualcolor(&mystat, &actstat);
if (actback == actstat) InvertColor(&mystat);
RGBForeColor(&mystat);
if (textmap) RGBBackColor(&myback);
}
temprect = myWindow->portRect;
temprect.top = temprect.bottom-15;
temprect.left = temprect.right-15;
EraseRect(&temprect);
MoveTo(temprect.left, temprect.bottom);
LineTo(temprect.left, temprect.top);
LineTo(temprect.right, temprect.top);
if (((WindowPeek)myWindow)->hilited) {
temprect.left += 3;
temprect.right = temprect.left + 7;
temprect.top += 3;
temprect.bottom = temprect.top + 7;
FrameRect(&temprect);
MoveTo(temprect.right, temprect.bottom-5);
Line(3, 0);
Line(0, 8);
Line(-8, 0);
Line(0, -3);
}
if (colormac && textmap) RGBBackColor(&realwhite);
if (!rgnok) SetClip(destrgn);
SetPort(psave);
}
xfGrowIcon()
{
GrafPtr psave;
Rect temprect;
GetPort(&psave);
SetPort(xdlgptr);
temprect = xdlgptr->portRect;
temprect.top = temprect.bottom-15;
temprect.left = temprect.right-15;
EraseRect(&temprect);
MoveTo(temprect.left, temprect.bottom);
LineTo(temprect.left, temprect.top);
LineTo(temprect.right, temprect.top);
if (((WindowPeek)xdlgptr)->hilited) {
temprect.left += 3;
temprect.right = temprect.left + 7;
temprect.top += 3;
temprect.bottom = temprect.top + 7;
FrameRect(&temprect);
MoveTo(temprect.right, temprect.bottom-5);
Line(3, 0);
Line(0, 8);
Line(-8, 0);
Line(0, -3);
}
SetPort(psave);
}
InitClip()
{
ClipRect(&(myWindow->portRect));
GetClip(cliprgn);
gr_rect = myWindow->portRect;
gr_rect.top = gr_rect.bottom-15;
gr_rect.left = gr_rect.right-15;
RectRgn(temprgn, &gr_rect);
DiffRgn(cliprgn, temprgn, destrgn);
SetClip(destrgn);
}
mousesel(function, location, doubleflag)
short function, location;
char doubleflag;
{
static short init_loc;
static char showsel;
static short sel_loc;
short toploc, bottomloc;
short startcol, toprow, endcol, bottomrow, t;
short scrtop, scrbottom, scrtop2, scrbottom2;
short scrstart, scrend, scrleft, scrright;
switch(function) {
case 0: /* initialization */
init_loc = location;
showsel = 0;
break;
case 1: /* display call */
case 2:
if (location != init_loc) {
if (showsel) {
if (location == sel_loc) break;
invsel(&lastsel);
}
/* define lastsel */
toploc = init_loc;
bottomloc = location;
if (toploc > bottomloc) {
toploc = location;
bottomloc = init_loc;
}
if (function == 2) {
bottomloc--;
if (doubleflag) wordadj(&toploc, &bottomloc, 0);
}
startcol = toploc % scrhsize;
endcol = bottomloc % scrhsize;
toprow = toploc / scrhsize;
bottomrow = bottomloc / scrhsize;
if ((function == 1) && (startcol > endcol)) {
t = startcol;
startcol = endcol;
endcol = t;
}
scrtop = toprow * vtxtsize + htxtstrt - 1;
scrbottom2 = bottomrow * vtxtsize + htxtstrt - 1;
scrtop2 = (toprow+1) * vtxtsize + htxtstrt -1;
scrbottom = (bottomrow+1) * vtxtsize + htxtstrt -1;
scrstart = startcol * htxtsize;
scrleft = 0;
scrend = (endcol+1) * htxtsize + 1;
scrright = scrhsize * htxtsize + 1;
if ((function == 1) ||
((startcol == 0) && (endcol == scrhoff)) ||
(toprow == bottomrow)) {
lastsel.x1 = lastsel.x2 = lastsel.x3 = lastsel.x8 =
scrstart;
lastsel.x4 = lastsel.x5 = lastsel.x6 = lastsel.x7 =
scrend;
lastsel.y1 = lastsel.y2 = lastsel.y3 = lastsel.y4 =
scrtop;
lastsel.y5 = lastsel.y6 = lastsel.y7 = lastsel.y8 =
scrbottom;
}
else {
lastsel.x1 = scrleft;
lastsel.y1 = scrtop2;
lastsel.x2 = scrstart;
lastsel.y2 = scrtop2;
lastsel.x3 = scrstart;
lastsel.y3 = scrtop;
lastsel.x4 = scrright;
lastsel.y4 = scrtop;
lastsel.x5 = scrright;
lastsel.y5 = scrbottom2;
lastsel.x6 = scrend;
lastsel.y6 = scrbottom2;
lastsel.x7 = scrend;
lastsel.y7 = scrbottom;
lastsel.x8 = scrleft;
lastsel.y8 = scrbottom;
if (startcol == 0) {
lastsel.x2 = lastsel.x3 = lastsel.x1;
lastsel.y1 = lastsel.y2 = lastsel.y3;
}
if (endcol == scrhoff) {
lastsel.x6 = lastsel.x7 = lastsel.x5;
lastsel.y5 = lastsel.y6 = lastsel.y7;
}
}
invsel(&lastsel);
showsel = 1;
sel_loc = location;
break;
}
if (showsel == 0) break;
invsel(&lastsel);
showsel = 0;
break;
case 3: /* termination */
if (showsel == 0) break;
invsel(&lastsel);
showsel = 0;
break;
default:
break;
}
}
invsel(r)
selcoord * r;
{
PenState ps;
GrafPtr gp;
static Pattern gray =
{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
selcoord s;
s = *r;
GetPort(&gp);
SetPort(myWindow);
GetPenState(&ps);
PenPat(gray);
PenMode(patXor);
MoveTo(s.x1, s.y1);
if ((s.x2 != s.x1) || (s.y2 != s.y1)) {
if ((s.y1 == s.y6) && (s.x6 < s.x2)) {
LineTo(s.x6, s.y6);
MoveTo(s.x2, s.y2);
}
else LineTo(s.x2, s.y2);
}
if ((s.x3 != s.x2) || (s.y3 != s.y2)) LineTo(s.x3, s.y3);
LineTo(s.x4, s.y4);
LineTo(s.x5, s.y5);
if ((s.x6 != s.x5) || (s.y6 != s.y5)) {
if ((s.y1 == s.y6) && (s.x6 < s.x2)) {
LineTo(s.x2, s.y2);
MoveTo(s.x6, s.y6);
}
else LineTo(s.x6, s.y6);
}
if ((s.x7 != s.x6) || (s.y7 != s.y6)) LineTo(s.x7, s.y7);
LineTo(s.x8, s.y8);
LineTo(s.x1, s.y1);
SetPenState(&ps);
SetPort(gp);
}